#include "gameLogo.h"
#include "json.h"
#include "Resource.h"

gameLogo::gameLogo(string& str)
{
	_color.a = _color.b = _color.g = _color.r = 0;
	string _str;
	_remove = false;
	int nowdraw, x, y;
	string str1 = "gameinformation/gameLogo/" + str + ".json";
	ifstream infile;
	infile.open(str1.c_str());

	Json::Reader reader;
	Json::Value root;
	if (!reader.parse(infile, root, false))
	{
		cout << "json error";
	}

	int size = root.size();

	Resource* r = 0;
	r = r->Instance();
	for (int i = 0; i < size; i++)
	{
		nowdraw = root[i]["draw"].asInt();
		x = root[i]["PointX"].asInt();
		y = root[i]["PointY"].asInt();
		_lastTime = root[i]["latTime"].asInt();
		_str = root[i]["kind"].asString();
	}
	if (_str == "fade")
	{
		_kind = FADE;
	}else if (_str == "move")
	{
		_kind = MOVETO;
	}
	_bitmap = r->_allLogo[nowdraw];
	_p.setPoint(x, y);
}

void gameLogo::draw()
{
	if (_kind == FADE)
	{
		al_draw_tinted_bitmap(_bitmap, _color,_p.x, _p.y, 0);
	}else if (_kind == MOVETO)
	{
		al_draw_bitmap(_bitmap, _p.x, _p.y, 0);
	}
}

void gameLogo::updata()
{
	_lastTime--;
	if (_lastTime < 0)
	{
		_remove = true;
	}
	if (!_remove)
	{
		if (_kind == FADE)
		{
			if (_color.a != 255)
			{
				_color.r++;			
				_color.g++;
				_color.b++;
				_color.a++;
			}
		}else if (_kind == MOVETO)
		{
			if (_p.y > 100)
			{
				_p.y--;
			}		
		}	
	}
}